<!DOCTYPE html>
<html lang="zh">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <!-- <script src="./vue.js"></script> -->
  <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
  <!-- <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.min.js"></script> -->
  <style>
    body {
      background-color: #ccc;
    }

    #app {
      width: 800px;
      margin: 20px auto;
      background-color: #fff;
      border: 4px solid blueviolet;
      border-radius: 1em;
      box-shadow: 3px 3px 3px rgba(0, 0, 0, .5);
      padding: 1em 2em 2em;
    }

    h3 {
      text-align: center;
    }

    .title {
      display: flex;
      justify-content: space-between;
      align-items: center;
      border: 1px solid #ccc;
      padding: 0 1em;
    }

    .title h4 {
      line-height: 2;
      margin: 0;
    }

    .container {
      border: 1px solid #ccc;
      padding: 0 1em;
    }

    .btn {
      /* 鼠标改成手的形状 */
      cursor: pointer;
    }
    input {
      width: 80px;
    }
  </style>
</head>

<body>
  <div id="app">
    <h3>案例：购物车结算</h3>
    <div>
      <p>手机： 价格 <input v-model="phonePrice"/> 数量 <input v-model="phoneNum"/> 小计 <label>{{phoneMoney}}</label>元</p>
      <p>电脑： 价格 <input v-model="computerPrice"/> 数量 <input v-model="computerNum"/> 小计 <label>{{computerMoney}}</label>元</p>
      <p title="托运及保价费">运费: <input v-model.number="freight"/>元</p>
      <p>共计：<label>{{totalMoney}}</label>元</p>
      <p>优惠：<label>{{discountMoney}}</label>元</p>
      <p>应付：<label>{{realMoney}}</label>元</p>
    </div>
    <hr>
    <div>
      <h4>优惠说明</h4>
      <p>如果两样商品的金额（不含运费）合计超过了5000元，则可减免100元</p>
      <p>如果两样商品的金额（不含运费）合计超过了8000元，则可减免200元</p>
      <h4>要求</h4>
      <p>在如上5个输入框中修改数值时，各项统计结果要实时更新</p>
    </div>
  </div>
  <script>
    new Vue({
      el: '#app',
      data: {
        phonePrice: 2989,
        phoneNum: 1,
        computerPrice: 6000,
        computerNum:1,
        freight: 10
      },
      computed: {
        phoneMoney () {
          return this.phonePrice * this.phoneNum
        },
        computerMoney () {
          return this.computerPrice * this.computerNum
        },
        totalMoney() {
          return this.phoneMoney + this.computerMoney
        },
        discountMoney () {
          if(this.totalMoney > 8000) {
            return 200
          } else if(this.totalMoney > 5000) {
            return 100
          }
          return 0
        },
        realMoney () {
          return this.totalMoney - this.discountMoney  + this.freight
        }
      }
    })
  </script>

</body>
</html>